package com.heima.UserService.Register;

import com.heima.UserService.RegisterService;
import com.heima.mapper.UserMapper;
import com.heima.pojo.User;
import com.heima.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class Rservice implements RegisterService {
    @Override
    public Integer selectUser(String usernames) {
        SqlSession session= MybatisUtils.getSqlSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> user = mapper.getUsername();
        for (User u:user){
            if (usernames.equals(u.getUsername())){
                return -1;
            }
        }
        return 1;
    }

    @Override
    public void addUser(String usernames,String password) {
        SqlSession session= MybatisUtils.getSqlSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        mapper.addUser(usernames,password);

    }
}
